package com.szrt.javaweb.demo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class RequestParamController {
	
	
	/*
	 * http://localhost:8080/mvn-springmvc-01-1609/requestparam01?username=zxx&age=33
	 */
	@RequestMapping("/requestparam01")
	public String requestparam01(HttpServletRequest request){
		String username = request.getParameter("username");
		String age = request.getParameter("age");
		System.out.println(username + ":"+ age);
		return "success";
	}
	
	
	/*
	 * 
	 * 缺点：username和 age都可以有 ，可以无
	 * http://localhost:8080/mvn-springmvc-01-1609/requestparam02?username=zxx&age=33
	 */
	@RequestMapping("/requestparam02")
	public String requestparam02(String username,Integer age){
		System.out.println(username + ":"+ age);
		return "success";
	}
	
	
	/*
	 * http://localhost:8080/mvn-springmvc-01-1609/requestparamwork?username=zxx&age=33
	 * @param entity
	 * @return
	 */
	@RequestMapping("/requestparamwork")
	public String requestparamwork(UserEntity entity){
		System.out.println(entity);
		return "success";
	}
	
	
	/*
	 * 缺点：username和 age都可以有 ，可以无
	 * username  必须要传过来   否则报400
	 * age       可传可不传
	 * http://localhost:8080/mvn-springmvc-01-1609/requestparam03?username=zxx&age=33
	 * 
	 */
	@RequestMapping("/requestparam03")
	public String requestparam03(
			@RequestParam(value="username",required=true) String name,
			@RequestParam(value="age",required=false) Integer aa){
		System.out.println(name + ":"+ aa);
		return "success";
	}
	
	

}
